<template>
	<view>
		<view class="tui-tabs">
			<scroll-view id="tab-bar" scroll-with-animation class="tui-scroll-h" :scroll-x="true" :show-scrollbar="false" style="border-bottom: 2upx solid #F8F8F8;">
				<view style="display: flex;">
					<view v-for="(tab, index) in tabBars" :id="tab.id" :data-current="index" @tap='tabSlect(tab)'>
						<view class="tui-tab-item-title" style="margin-left: 140upx;" :class="{ 'tui-tab-item-title-active': tabIndex == tab.id }">{{ tab.name }}</view>
					</view>
				</view>
			</scroll-view>
		</view>
		<!-- #ifdef H5 -->
		<view style="display: flex;flex-wrap: wrap;padding-bottom: 30upx;margin-left: 13upx;margin-top: 80upx;">
			<!-- #endif -->
			<!-- #ifndef H5 -->
			<view style="display: flex;flex-wrap: wrap;padding-bottom: 0upx;margin-left: 15rpx;margin-top: 80upx;">
				<!-- #endif -->
				<view style="width: 350upx;height: 510upx;background-color: #FFFFFF; border-radius: 20upx;margin-left: 10upx; margin-top: 15upx;box-shadow: rgba(183, 183, 183, 0.3) 1px 1px 10px 1px;"
				 @tap='goDetail(item.id)' v-for="(item,index) in homegoodsList" :key='index' v-if="homegoodsList.length > 0">
					<image lazy-load="true" :src="item.coverImg" style="width: 350upx;height: 340upx;border-top-left-radius:20upx;border-top-right-radius:20upx;"></image>
					<view style="padding: 16upx 2upx 16upx 16upx;">
						<view style="width: 100%;height:  60upx;">
							<text class="limapboxqing2">{{ item.title }}</text>
						</view>
					</view>
					<view style="padding: 0rpx 15rpx;display: flex;margin:20rpx 0">
						<view style="font-size: 38upx;color: #FF2A47;"> {{item.price}}</view>
						<view style="font-size: 24upx;color: #999999;margin-left: 10rpx;margin-top: 8upx;">{{item.sales}}人已购买</view>
					</view>
				</view>
				<!-- 悬浮上拉 -->
				<view class="scroll_top" @tap="topScrollTap" v-bind:class="[scrollTop ? 'active' : '','']" style="bottom: 56px;">
					<text class="iconfont icon-shangla"></text>
				</view>
				<!-- 加载更多提示 -->
				<view class="s-col is-col-24" v-if="homegoodsList.length > 0">
					<load-more :loadingType="loadingType" :contentText="contentText"></load-more>
				</view>
				
				<!-- 加载更多提示 -->
				<empty v-if="homegoodsList.length === 0" des="暂无积分商品信息" show="false"></empty>
			</view>
		</view>
</template>

<script>
	export default {
		data() {
			return {
				tabIndex: '0',
				tabStatus: 'createAt',
				//综合createAt 销量sales 佣金比例commissionPrice 超低价price
				tabBars: [{
						name: '综合',
						id: '0',
						status: 'createAt'
					},
					{
						name: '销量',
						id: '1',
						status: 'sales'
					},
					{
						name: '超低价',
						id: '2',
						status: 'price'
					}
				],
				homegoodsList: [],
				page: 0,
				size: 10,
				loadingType: 0,
				scrollTop: false,
				contentText: {
					contentdown: "上拉显示更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多数据了"
				}
			}
		},
		onLoad() {
			this.getList();
		},
		methods: {
			tabSlect(item) {
				this.switchTab(item.id);
			},
			switchTab(index) {
				this.page = 0;
				this.tabIndex = index;
				this.tabStatus = this.tabBars[index].status;
				this.list = [];
				this.getList('switch');
			},
			goDetail(id) {
				uni.navigateTo({
					url: './jifendetail?ordersId=' + id
				});
			},
			getList(type) {
				this.loadingType = 1;
				this.$Request.getT('/goods/userList?page=' + this.page + '&size=' + this.size + '&type=&title=&sort=' +
					this.tabStatus + '&isJiFenGoods=1').then(
					res => {
						if (res.status === 0) {
							if (this.page === 0 || res.status) {
								this.homegoodsList = [];
							}
							res.data.content.forEach(d => {
								d.descrition = '';
								d.sales = d.sales > 10000 ? (d.sales / 10000).toFixed(1) + '万' : d.sales;
								this.homegoodsList.push(d);
							});
							if (res.data.content.length === this.size) {
								this.loadingType = 0;
							} else {
								this.loadingType = 3;
							}
						} else {
							this.loadingType = 2;
						}
						uni.hideLoading();

						if (type === "Refresh") {
							uni.stopPullDownRefresh(); // 停止刷新
						}
					});
			},
			// getList(type) {
			// 	this.$Request.getT('/goods/list?page=' + this.page + '&size=' + this.size + '&status=' + 1 + '&isJiFenGoods=1').then(res => {
			// 		if (res.status === 0) {
			// 			if (this.page === 0 || res.status) {
			// 				this.homegoodsList = [];
			// 			}
			// 			res.data.content.forEach(d => {
			// 				this.homegoodsList.push(d);
			// 			});
			// 		}
			// 	});
			// },
			topScrollTap: function() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
			}
		},
		onPageScroll: function(e) {
			this.scrollTop = e.scrollTop > 200;
		},
		onReachBottom: function() {
			this.page = this.page + 1;
			this.getList('');
		},
		onPullDownRefresh: function() {
			this.page = 0;
			this.min_id = 1;
			this.getList("type");
		}
	}
</script>

<style lang="less" scoped>
	@import '../../../static/less/index.less';
	@import '../../../static/css/index.css';

	page {
		background: #F5F0F0;
	}

	.tui-tabs {
		flex: 1;
		flex-direction: column;
		overflow: hidden;
		background-color: #fafafa;
		/* #ifdef MP-ALIPAY || MP-BAIDU */
		height: 100vh;
		/* #endif */
	}

	.tui-scroll-h {
		width: 750rpx;
		height: 80rpx;
		background-color: #ffffff;
		flex-direction: row;
		/* #ifndef H5 */
		position: fixed;
		top: 0;
		left: 0;
		z-index: 999;
		/* #endif */
		/* #ifndef APP-PLUS */
		white-space: nowrap;
		/* #endif */
		/* #ifdef H5 */
		position: fixed;
		top: 44px;
		left: 0;
		z-index: 999;
		/* #endif */
	}

	.tui-line-h {
		/* #ifdef APP-PLUS */
		height: 1rpx;
		background-color: #cccccc;
		/* #endif */
		position: relative;
	}

	/* #ifndef APP-PLUS*/
	.tui-line-h::after {
		content: '';
		position: absolute;
		border-bottom: 1rpx solid #cccccc;
		-webkit-transform: scaleY(0.5);
		transform: scaleY(0.5);
		bottom: 0;
		right: 0;
		left: 0;
	}

	/* #endif */

	.tui-tab-item {
		/* #ifndef APP-PLUS */
		display: flex;
		/* #endif */
		// flex-wrap: nowrap;
		// padding-left: 34rpx;
		// padding-right: 34rpx;
	}

	.tui-tab-item-title {
		color: #555;
		font-size: 30rpx;
		height: 80rpx;
		line-height: 80rpx;
		flex-wrap: nowrap;
		/* #ifndef APP-PLUS */
		white-space: nowrap;
		/* #endif */
	}

	.tui-tab-item-title-active {
		color: #E10A07;
		font-size: 32upx;
		font-weight: bold;
		border-bottom-width: 6upx;
		text-align: center;
	}
	
	.limapboxqing2 {
	
		font-size: 28upx;
		color: #333333;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}
</style>
